package sz.szsmk.citizencard.mvp.dzsmkpresenter;

import com.google.gson.Gson;
import sz.szsmk.citizencard.model.network.dzbean.req.CommonRequest;
import sz.szsmk.citizencard.model.network.dzbean.res.BalanceVo;
import sz.szsmk.citizencard.model.network.dzbean.res.GetBalanceResponse;
import sz.szsmk.citizencard.mvp.MineMvpView;
import sz.szsmk.citizencard.retrofitrxjava.ErrorAction;
import sz.szsmk.citizencard.smkretrofit.NetworkDateSource;
import sz.szsmk.citizencard.util.CommonUtils;
import sz.szsmk.citizencard.util.ObjectSignatureUtil;

import javax.inject.Inject;

import rx.functions.Action1;

/**
 * Created by chensf on 17/10/4.
 */

public class MinePresenter extends PersonInfoQueryPresenter<MineMvpView> {

    @Inject
    NetworkDateSource mNetworkDateSource;

    @Inject
    public MinePresenter() {
        getComponent().inject(this);
    }


    public void getBalance() {
        checkViewAttached();

        CommonRequest commonRequest = ObjectSignatureUtil.getCommonRequest();
        mNetworkDateSource.getBalance(commonRequest, new Action1<GetBalanceResponse>() {
            @Override
            public void call(GetBalanceResponse sysResponse) {
                String code = sysResponse.getCode();
                if (code.equals("0000")) {
                    GetBalanceResponse.DataBean data = sysResponse.getData();
                    if (data == null) {
                        return;
                    }
                    String json = new Gson().toJson(data);
                    BalanceVo balanceVo = new Gson().fromJson(json, BalanceVo.class);
                    if (balanceVo == null) {
                        return;
                    }
                    getMvpView().onGainBalance(sysResponse);

                } else {
                    getMvpView().onGainBalanceFail();
                }
            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {

            }
        });

    }

}
